import reactive from "./reactive.js";
import { effect } from "./effect.js";
const obj = {
  a: 1,
  b: 2,
  // get c() {
  //   return this.a + this.b;
  // },
  c: 3,
};
const arr = [{ a: 1 }, 1, 3, 4];
const state = reactive(obj);
const state2 = reactive(arr);
// 依赖收集测试
function fn() {
  console.log("fn");
  // state.a;
  // for (const element in state) {
  //   state[element];
  // }

  // state2[1];
  // (function () {
  //   console.log("fn2");
  //   state2[2];
  // })();
  // for (const element of state2) {
  // }

  // if (state.a === 1) {
  //   state.b;
  // } else {
  //   state.c;
  // }

  // effect(() => {
  //   console.log("inner");
  //   state.a;
  // })
  // state.b;

  // state.a++;
  state.a;
  state.b;
}

// 在收集依赖函数时，我们将“决定该函数是否要收集依赖”的权限交给用户自行决定
effect(fn);
// state2[1] = 2;
// state2[2] = 2;
// state.a = 2;
// state.b = 3;
// state.a = 1;
// state.d = 4
// delete state.c;
// const enffectFn = effect(fn, {
//   lazy: true,
//   scheduler: (effectFn) => {
//     console.log("scheduler");
//   },
// });
// enffectFn();

state.a++;
state.b++;
state.a++;
state.b++;
state.a++;
state.b++;
state.a++;
state.b++;
state.a++;
state.b++;
state.a++;
state.b++;
state.a++;
state.b++;
// console.log("end", state.a);
